<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Coupon as ModelCoupon;
use app\common\model\coupon\Log;
use ErrorException;
use think\Db;

/**
 * 优惠券接口
 */
class Coupon extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /**
     * 我的优惠券
     *
     */
    public function my_coupon()
    {
        $get = request()->get();
        extract($get);
        if (!isset($state) ) {
            $this->error('参数错误');
        }
        $user_id =  $this->auth->id;
        //更新过期优惠券
        Log::editState($user_id);
        $couponLog = new Log();
        if (isset($money) && $money) {
            $couponLog->where('money', '<=', $money);
        }
        $couponLog->where('user_id', $user_id);
        $couponLog->where('state', $state);

        $list =  $couponLog->order('createtime desc')->paginate(10);
        $this->success('请求成功', $list);
    }
}
